package com.madarasan.SkiDroid;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.maps.MapActivity;
import com.madarasan.providers.ShowProviderList;
import com.madarasan.resorts.ShowResortList;
import com.madarasan.weather.ShowResortWeather;

public class GlobalMenuActivity extends MapActivity {
	
	private static final int NOTIFICATION_ID=2;
	private static final int REQUEST_CODE=1;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection

		Boolean resortSelected = ((MyApplication) this.getApplication())
				.getResortSelected();

		Log.i("GlobalMenuActivity resortSelected", resortSelected.toString());

		if (resortSelected.equals(false))
			if (item.getItemId() != R.id.select_city
					& item.getItemId() != R.id.gethelp)

			{
				Toast.makeText(
						getApplicationContext(),
						getApplicationContext().getResources().getString(
								R.string.noresortselected), Toast.LENGTH_SHORT)
						.show();
				return super.onOptionsItemSelected(item);

			}

		switch (item.getItemId()) {
		case R.id.select_city:
			startActivity(new Intent(this, ShowResortList.class));

			return true;

		case R.id.weather:
			startActivity(new Intent(this, ShowResortWeather.class));

			return true;

//		  case R.id.routes:
//		  startActivity(new Intent(this, ShowResortWeather.class));
//			return true;

		case R.id.webcam:
			startActivity(new Intent(this, ShowResortWebcam.class));

			return true;

		case R.id.equipments:
			startActivity(new Intent(this, ShowProviderList.class));

			return true;

		case R.id.gethelp:
			startActivity(new Intent(this, MyPreferencesActivity.class));

			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	public void displayNotification(String msg)
	{
	NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	Notification notification = new Notification(R.drawable.skidroid, msg, System.currentTimeMillis());

	// The PendingIntent will launch activity if the user selects this notification
	PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_CODE, new Intent(this, GlobalMenuActivity.class), 0);

	notification.setLatestEventInfo(this, "SkiDroid", msg, contentIntent);

	manager.notify(NOTIFICATION_ID, notification);

	}

}
